﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace KinnectInput
{
    public class KinectDataIntepretHelper
    {
        public static float firgureAxisRotation(Vector3 originPosition, Vector3 targetPosition, Vector3 pointOfView)
        {
            float rot = 0;

            targetPosition = Vector3.Normalize(targetPosition - originPosition);
            originPosition = Vector3.Normalize(originPosition);

            Vector2 Origin = Vector2.Zero;
            Vector2 Target = Vector2.Zero;
            if (pointOfView == Vector3.Up)
            {
                originPosition = Vector3.Normalize(originPosition + Vector3.Forward);
                Origin = new Vector2(originPosition.X, originPosition.Z);
                Target = new Vector2(targetPosition.X, targetPosition.Z);
            }
            else if (pointOfView == Vector3.Forward)
            {
                originPosition = Vector3.Normalize(originPosition + Vector3.Up);
                Origin = new Vector2(originPosition.X, originPosition.Y);
                Target = new Vector2(targetPosition.X, targetPosition.Y);
            }
            else if (pointOfView == Vector3.Right)
            {
                originPosition = Vector3.Normalize(originPosition + Vector3.Negate(Vector3.Up));
                Origin = new Vector2(originPosition.Y, originPosition.Z);
                Target = new Vector2(targetPosition.Y, targetPosition.Z);
            }

            rot = (float)Math.Acos(Vector2.Dot(Target, Origin));
            rot = MathHelper.ToDegrees(rot);

            return rot;

        }
        public static string VectorConverter2Decimals(Vector3 v)
        {
            string s;
            s = string.Format("{0:00}", v.X) + "," + string.Format("{0:00}", v.Y) + "," + string.Format("{0:00}", v.Z);
            return s;
        }
        
        //private float figureRotation(Vector3 originFwd, Vector3 targetPosition, Vector3 pointOfView)
        //{
        //    float rot = 0;

        //    //sin normalizar los vectores no funcionaba a ver ahora
        //    targetPosition = Vector3.Normalize(targetPosition - originFwd);
        //    originFwd = Vector3.Normalize(originFwd);

        //    Vector2 Origin = Vector2.Zero;
        //    Vector2 Target = Vector2.Zero;
        //    if (pointOfView == Vector3.Up)
        //    {
        //        Origin = new Vector2(originFwd.X, originFwd.Z);
        //        Target = new Vector2(targetPosition.X, targetPosition.Z);
        //    }
        //    else if (pointOfView == Vector3.Forward)
        //    {
        //        Origin = new Vector2(originFwd.X, originFwd.Y);
        //        Target = new Vector2(targetPosition.X, targetPosition.Y);
        //    }
        //    else if (pointOfView == Vector3.Right)
        //    {
        //        Origin = new Vector2(originFwd.Y, originFwd.Z);
        //        Target = new Vector2(targetPosition.Y, targetPosition.Z);
        //    }

        //    rot = (float)Math.Acos(Vector2.Dot(Target, Origin));
        //    rot = MathHelper.ToDegrees(rot);

        //    //nomes torna rotacion relativa sense signe de 0 a 180
        //    return rot;

        //}
    }
}
